package com.neusoft.SPNursingHome.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.neusoft.SPNursingHome.po.CareLevel;
import com.neusoft.SPNursingHome.po.ResponseBean;
import com.neusoft.SPNursingHome.service.CareLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/CareLevelController")
public class CareLevelController {
    @Autowired
    private CareLevelService careLevelService;

    // 护理级别列表
    @GetMapping("/listCareLevel")
    public ResponseBean<List<CareLevel>> listCareLevel() {
        return careLevelService.listCareLevel();
    }

    // 根据状态查询护理级别
    @GetMapping("/listCareLevelByStatus")
    public ResponseBean<IPage<CareLevel>> listCareLevelByStatus(Boolean careLevelStatus, @RequestParam(defaultValue = "1") long page,
                                                                @RequestParam(defaultValue = "10") long size) {
        if (careLevelStatus == null) {
            return new ResponseBean<>(500, "状态参数不能为空");
        }
        return careLevelService.listCareLevelByStatus(careLevelStatus, page, size);
    }

    // 根据状态查询护理级别
    @GetMapping("/listCareLevelByStatusNP")
    public ResponseBean<List<CareLevel>> listCareLevelByStatusNP(Boolean careLevelStatus) {
        if (careLevelStatus == null) {
            return new ResponseBean<>(500, "状态参数不能为空");
        }
        return careLevelService.listCareLevelByStatusNP(careLevelStatus);
    }

    // 修改护理级别（只能修改状态）
    @PostMapping("/updateCareLevelStatus")
    public ResponseBean<Integer> updateCareLevelStatus(@RequestBody CareLevel request) {
        if (request.getCareLevelId() == null || request.getCareLevelStatus() == null) {
            return new ResponseBean<>(500, "护理级别ID和状态参数均不能为空");
        }
        return careLevelService.updateCareLevelStatus(request.getCareLevelId(), request.getCareLevelStatus());
    }

    // 添加护理级别
    @PostMapping("/addCareLevel")
    public ResponseBean<Integer> addCareLevel(@RequestBody CareLevel request) {
        System.out.println(request.getCareLevelName()+request.getCareLevelStatus());
        if (request == null || request.getCareLevelName() == null || request.getCareLevelStatus() == null) {
            return new ResponseBean<>(500, "护理级别名称和状态参数均不能为空");
        }
        return careLevelService.addCareLevel(request.getCareLevelName(), request.getCareLevelStatus());
    }
}
